package cn.hzxs.zjn.studentmanagement.dao;

import cn.hzxs.zjn.studentmanagement.domain.Score;
import cn.hzxs.zjn.studentmanagement.domain.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;


/**
 * @Author: Zjn ; Bring it on !!!
 * @Date: 2021/3/23 0023 14:29
 * Note:
 */

@Repository
//@Repository    //向spring注入该实例@Autowired

public interface UserMapper {
    /*-----------------------登录功能-----------------------*/
    /*@Results(id = "UserMap",value = {
            @Result(column = "user_id",property = "USERID",javaType = Integer.class),
            @Result(column = "user_name",property = "USERNAME",javaType = String.class),
            @Result(column = "password",property = "PASSWORD",javaType = String.class),
            @Result(column = "user_icon",property = "USERICON",javaType = String.class),
            @Result(column = "phone", property = "PHONE", javaType = String.class),
            @Result(column = "studio_id",property = "STUDIOID",javaType = Integer.class),
            @Result(column = "role",property = "ROLE",javaType = Integer.class)
    })*/
    @Select("select user_id,role from user where phone=#{phone}")
    Map findUserIdByPhone(String phone);
    @Select("select user_id,role from user where user_name=#{username}")
    Map findUserIdByUserName(String username);

    @Select("select count(*) from user where user_name=#{username}")
//    @ResultMap(value={"UserMap"})
    Integer ifExistUsername(String username);
    @Select("select count(*) from user where phone=#{phone}")
    Integer ifExistPhone(String phone);

    @Select("select password from user where user_name=#{username}")
    String findPasswordByUsername(String username);
    @Select("select password from user where phone=#{phone}")
    String findPasswordByPhone(String phone);


    /*-----------------------注册功能-----------------------*/
    @Insert("insert into user (user_name,password,phone,studio_id,role)" +
            "values (#{USERNAME},#{PASSWORD},#{PHONE},#{STUDIOID},#{ROLE})")
    void userReg(User user);

    /*-----------------------查询---------------------------*/
    @Select("select user_name,user_icon from user where user_id=#{author_id};")
    Map<String,String> findUsernameIconByAuthorId(Integer author_id);

    /*查询所有用户信息*/
    @Select("select user_name as userName,user_id as userId,user_icon as userIcon from user;")
//    @ResultMap("UserMap")
    List<Map> userGet();

    /*查询指定用户ID的用户信息*/
    @Select("select user_id as userId,user_name as userName,user_icon as userIcon from user" +
            " where user_id=#{userId}")
//    @ResultMap("UserMap")
    Map personal(Integer userId);

    @Select("select user_name as userName,user_id as userId,user_icon as userIcon from user" +
            " where user.role=0;")
    List<Map> teacher_planGet();


//     uploadIcon
}
